package com.atguigu.lease.web.admin.tasks;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyTask {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    //定时注解，每天一点检查一次
    @Scheduled(cron = "0 0 1 * * *")
    public void taskLeaseAgreement(){
        // 1 租约结束日期小于当前日期
        // 2 且租约状态为 2，5，7
        // 3 则修改租约状态

        LambdaQueryWrapper<LeaseAgreement> leaseAgreementLambdaQueryWrapper = new LambdaQueryWrapper<>();
        leaseAgreementLambdaQueryWrapper.lt(LeaseAgreement::getLeaseEndDate,new Date());
        leaseAgreementLambdaQueryWrapper.in(LeaseAgreement::getStatus, LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING,LeaseStatus.SIGNING);
        leaseAgreementService.update(leaseAgreementLambdaQueryWrapper);
    }
}
